package com.znxs.zuopao_c.once;

import com.znxs.zuopao_c.mapper.UserMapper;
import com.znxs.zuopao_c.domain.User;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import javax.annotation.Resource;

@Component
public class InsertUsers {
    @Resource
    private UserMapper userMapper;

    /**
     * 批量插入用户
     */
    // @Scheduled(fixedDelay = 50000)
    public void doInsertUsers(){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        final int INSERT_NUM = 1000;
        for (int i = 0; i < INSERT_NUM; i++) {
            User user = new User();
            user.setUsername("假人");
            user.setUserAccount("JiaRen");
            user.setAvatarUrl("https://q1.qlogo.cn/g?b=qq&nk=1686381086&s=100");
            user.setGender(0);
            user.setUserPassword("12345678910");
            user.setPhone("17367438763");
            user.setEmail("1686381086@qq.com");
            user.setTags("[]");
            user.setUserStatus(0);
            user.setUserRole(0);
            user.setPlantCode("1111111");

            userMapper.insert(user);
        }
        stopWatch.stop();
        long totalTimeMillis = stopWatch.getTotalTimeMillis();
        System.out.println("使用了"+totalTimeMillis+"ms");
    }
}
